package com.boot.until;

import com.baidu.aip.speech.AipSpeech;
import com.baidu.aip.speech.TtsResponse;
import lombok.extern.slf4j.Slf4j;

import java.util.HashMap;

/**
 * 百度请求专用
 */
@Slf4j
public class BaiduUntil {
    //设置APPID/AK/SK
    public static final String APP_ID = "10767176";
    public static final String API_KEY = "mctUCzSzTpU5cXcQfdrDcagc";
    public static final String SECRET_KEY = "kpypSf2eFGOZQnCkqQxe3INVcU4r3l63";


    /**
     * 获取百度的语音合成
     * @param src
     * @return
     */
    public static byte[] getBaoduAudio(String src){
        // 初始化一个AipSpeech
        AipSpeech client = new AipSpeech(APP_ID, API_KEY, SECRET_KEY);
        // 调用接口
        // 设置可选参数
        HashMap<String, Object> options = new HashMap<String, Object>();
        options.put("spd", "5");
        options.put("pit", "5");
        options.put("per", "4");
        TtsResponse res = client.synthesis(src, "zh", 1, options);
        byte[] data = res.getData();
        return data;
    }

    public static void main(String[] args) {
        byte[] bytes=getBaoduAudio ( "我叫小小军");
    }


}
